﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using Projectmanagement.Entity;
using Projectmanagement.Utl;
using ProjectManagement.Models;
using Telerik.Web.Mvc;


namespace Projectmanagement.Controllers
{
    [RoleRequired]
    public class TaskStateController : Controller
    {
        public ActionResult Index()
        {
            return View();
        }

        [GridAction]
        public ActionResult _SelectIndex()
        {
            return View(new GridModel(DQ.GetTaskStates()));
        }

        [AcceptVerbs(HttpVerbs.Post)]
        [GridAction]
        public ActionResult _SaveAjaxEditing(int id)
        {
            var item = CH.GetDataByID<TaskState>(id);
            if (TryUpdateModel(item))
            {
                CH.Edit<TaskState>(item);
            }
            return View(new GridModel(DQ.GetTaskStates()));
        }

        [AcceptVerbs(HttpVerbs.Post)]
        [GridAction]
        public ActionResult _InsertAjaxEditing()
        {
            var item = new TaskState();

            if (TryUpdateModel(item))
            {

                CH.Create<TaskState>(item);
            }
            return View(new GridModel(DQ.GetTaskStates()));
        }

        [AcceptVerbs(HttpVerbs.Post)]
        [GridAction]
        public ActionResult _DeleteAjaxEditing(int id)
        {
            CH.Delete<TaskState>(id);
            return View(new GridModel(DQ.GetTaskStates()));
        }

    }
}
